<?php
include_once 'kelas/amankanParam.php';
include_once 'kelas/fungsi.php';
include_once 'kelas/record.php';
include_once 'kelas/kategori.php';

include_once 'kelas/produk.php';
include_once 'kelas/customer.php';
include_once 'kelas/pemesanan.php';
$o = new fungsi();
echo $objFungsi->buatJudul('Histori Pesanan');
$dtPesan = $objPemesanan->getHistoriOrder();
//$objFungsi->var_dump($dtPesan);
?>

<div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">
<th>No</th><th>No Order</th><th>Tanggal</th><th>Status</th><th>Detail</th></tr>
    </thead>
    <tbody>
        <?php
        if ($dtPesan['total'] == 0) {
            
        } else {
            $no = 1;
            foreach ($dtPesan['result'] as $dtPsn) {
                ?>
                <tr><td><?php echo $no++; ?></td><td><?php echo $dtPsn['id_pemesanan']; ?></td>
                    <td><?php echo date('d F Y, H:i:s', strtotime($dtPsn['tanggal'])); ?></td>
                    <td><?php echo $objPemesanan->statusOrder($dtPsn['status_pesan']); ?></td>
                    <td><a 
                        class="button_2" 
                        href="<?php echo BASEURL . '?v=myprofile&p=orderedlist&id=' . $dtPsn['id_pemesanan']; ?>">Detail</a></td>
                </tr>
                <?php
            }
        }
        ?>
    </tbody>
</table>
</div>
<?php
if (isset($dtGet['id'])) {
    echo $objFungsi->buatJudul('Detail');
    $getDetail = $objPemesanan->getDataPesan($dtGet['id']);
    if($getDetail['header']['success']==false){
        echo '<h3>Detail Tidak Dapat Ditemukan Untuk Nomor Order '.(isset($dtGet['id'])?$dtGet['id']:'').'</h3>';
    }else{
        $hdr = $getDetail['header'];
        $dtl = isset($getDetail['detail'])?$getDetail['detail']:'';
        ?>
        <div style="width:100%;text-align:center">
            <h3>Status Pesanan:<?php echo $objPemesanan->statusOrder($hdr['status_pesan']); ?></h3>
            <h3 style="color:red"><?php echo strlen($hdr['ket_admin'])>0?"Keterangan: ".$hdr['ket_admin']:""; ?></h3>
        </div>
        <div style="width:30%;float:left">
        <h4>Nomor Order:</h4><?php echo $hdr['id_pemesanan']; ?><br/>
        <h4>Tanggal Pemesanan:</h4><?php echo $hdr['tanggal']; ?><br/>
        <h4>Penerima</h4>
        <p>Nama: <?php echo $hdr['nama_penerima']; ?></p>
        <p>No Telepon: <?php echo $hdr['telepon_penerima']; ?></p>
        <p>Email: <?php echo $hdr['email_penerima']; ?></p>
        <p>Alamat: <?php echo $hdr['alamat_penerima']; ?></p>
        <p>Kota: <?php echo $hdr['kota_penerima']; ?></p>
        <h4>Biaya Pengiriman Ke <?php echo $hdr['kota_penerima'] ?></h4>
        <p><?php echo $objFungsi->formatUang($hdr['biaya_ongkir']); ?></p>
        <h4>Pembayaran</h4>
        <p>Ke: <?php echo $hdr['bank'].'&nbsp;&nbsp;Rek:'.$hdr['norek']; ?></p>
        <p>Atas Nama: <?php echo $hdr['atasnama']; ?></p>
        <p>Cabang: <?php echo $hdr['cabang']; ?></p>
        <h4>Pesan Tambahan</h4>
        <p><?php echo $hdr['pesan_tambahan']; ?></p>
        <hr/>
        </div>
        <div style="width:65%;float:right">
            
<div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">
                        <th>Nama Produk</th>
                        <th>Gambar</th>
                        <th>Diskon</th>
                        <th>Bayar</th>
                        <th>Qty</th>
                        <th>Subtotal</th>
                    </tr>
                </thead>
            <?php
            $totalByr = 0;
             foreach ($dtl as $key => $value) {

                   ?>
                   <tr>
                    <td><?php echo $value['nama']; ?></td>
                    <td><img style="width:30px;height:40px" src="<?php echo BASEURL.'produk/'.$value['gambar']; ?>"> </td>
                    <td><?php echo $value['diskon']; ?>%</td>
                    <td>
<?php $hrgByr =($value['diskon']>0)?$value['harga_bayar']-($value['harga_bayar']*($value['diskon']/100)):$value['harga_bayar'];echo $objFungsi->formatUang($hrgByr); ?>
                    </td>
                    <td><?php echo $value['jumlah_buy'] ?></td>
                    <td><?php echo $objFungsi->formatUang($hrgByr*$value['jumlah_buy']); ?></td>
                   </tr>

                   <?php
                   $totalByr +=($hrgByr*$value['jumlah_buy']);

            } ?>
            <tfoot>
                <tr>
                    <th colspan="5">Total: </th>
                    <th><?php echo $objFungsi->formatUang($totalByr); ?>
                </th>
                </tr>
            </tfoot>
            </table>
        </div>
            <h4>Jumlah yang harus ditransfer:</h4>
            <p><?php echo $objFungsi->formatUang($hdr['biaya_ongkir']+$totalByr); ?></p>
            <h4>Status Pemesanan</h4>
            <p><?php echo $objPemesanan->statusOrder($hdr['status_pesan']); ?></p>
            <h4>Keterangan</h4>
            <p><?php echo strlen($hdr['ket_admin'])>0?$hdr['ket_admin']:"(tidak ada)"; ?></p>
        </div>
        <?php
    };
//    $objFungsi->var_dump($dtl[0],false);
}
?>